<?php
use yii\helpers\Url;
use yii\widgets\LinkPager;

?>

<?= $this->render('header'); ?>

<div class="row borB">
	<div class="container">
		<ul class="nav nav-tabs mt10 smNav">
			<li class="active"><a href="javascript:;" style="color: #575757;">店铺预约</a></li>
			<li><a href="<?= Url::to(['make', 'type' => 2]) ?>">APP预约</a></li>
		</ul>
	</div>
</div>

<div id="service-log" class="container mt20">
	<div class="table-responsive">
		<?php if(empty($list)){?>
		<table class="table table-bordered">
			<thead>
			<tr>
				<th>会员</th>
				<th>预约项目</th>
				<th>美容师</th>
				<th>预约时间</th>
				<th>预约房间</th>
				<th>记录时间</th>
				<th>状态</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
			<tr>
				<td colspan="8" align="center"><img src="<?=Yii::getAlias('@web/backend/img/nodata.gif');?>"></td>
			</tr>
			</tbody>
		</table>
		<?php }else{?>
		<table class="table table-bordered">
			<thead>
			<tr>
				<th>会员</th>
				<th>预约项目</th>
				<th>美容师</th>
				<th>预约时间</th>
				<th>预约房间</th>
				<th>记录时间</th>
				<th>状态</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>

			<?php foreach($list as $service): ?>
			<tr>
				<td class="exc">
					<img class="person role" aid="<?= $service['service_id'] ?>" src="" alt="头像">
					<div class="exc-con">
						<div><?= $service['service_member_name'] ?></div>
						<div><?= $service['service_member_phone'] ?></div>
					</div>
				</td>
				<td><?= $service['extends'][0]['beautycartd_name'] ?></td>
				<td><?= $service['extends'][0]['employee_name'] ?></td>
				<td><?= substr($service['make_time'], 0, 16) ?></td>
				<td><?= $service['room_name'] ?></td>
				<td><?= substr($service['service_addtime'], 0, 10); ?></td>
				<td class="jl_status_<?= $service['service_id'] ?>">预约中</td>
				<td>
					<a class="btnBor jl_start_<?= $service['service_id'] ?>" href="javascript:startServer(<?= $service['service_id'] ?>, <?= $service['service_member_id'] ?>)">开始服务</a>
					<a class="btnBor" href="javascript:cancelServer(<?= $service['service_id'] ?>)">取消预约</a>
				</td>
			</tr>
			<?php endforeach; ?>

			</tbody>
		</table>
		<?php }?>
	</div>
	<div class="page">
		<?= LinkPager::widget([
			'pagination' => $page,
			// 'hideOnSinglePage' => true
		]); ?>
	</div>

</div>

<script>
	<?php $this->beginBlock('js_index') ?>

	$(function(){
		$('.role').each(function () {
			var $id =$(this).attr('aid');
			$(this).attr('src','/backend/img/member/ico'+($id%20+1)+'.png');
		});

		function openPage() {
			var obj = $(this);
			var url = obj.attr('durl');
			layer.open({
				type: 2,
				title: '',
				shadeClose: false,
				shade: 0.8,
				maxmin: true, //开启最大化最小化按钮
				area: ['40%', '50%'],
				content: url
			});
		}
		$('.remark').on('click', openPage);
	});

	/**
	 * 开始服务
	 * @param service_id 服务id
	 */
	function startServer(service_id, member_id) {
		layer.open({
			type: 2,
			title: '开始服务',
			shadeClose: false,
			shade: 0.8,
			maxmin: true, //开启最大化最小化按钮
			area: ['795px', '525px'],
			content: '<?= Url::to(['servicestart']) ?>?s_id=' + service_id + '&m_id=' + member_id
		});
		/*$.get("<?= Url::to(['changes']) ?>", {id:service_id, status:1}, function(status) {
			if (status) {
				var obj = $('.jl_start_' + service_id);
				obj.addClass('active');
				obj.attr({href:'javascript:;'});
				$('.jl_status_' + service_id).html('开始服务');
			}
		});*/
	}

	/**
	 * 取消预约
	 * @param service_id 服务id
	 */
	function cancelServer(service_id) {
		$.get("<?= Url::to(['changes']) ?>", {id:service_id, status:0}, function(status) {
			location.reload();
		});
	}

	<?php $this->endBlock() ?>
	<?php $this->registerJs($this->blocks['js_index'], $this::POS_END); ?>
</script>